package com.open.common.task;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.open.loan.domain.req.Apply_info;
import com.open.loan.domain.req.Basic_info;
import com.open.loan.utils.HttpUtil;

import java.util.HashMap;
import java.util.Map;

public class CreditCardTest {

	public static String client_secret="a0d730a9ebb4411f881b52f5e6d5361a";
	public static String access_token="2b933652ff3a4872955f8acf22dccd60";

	/*//2.2.1提交申请表单接口
	public static JSONObject ApplyFromPost(HashMap hashMap) {
		
	}
	//提交采集请求接口(账号密码)
	public static JSONObject startCaiji(String token) {
		
		return jsonObject;
	}*/
	
	//提交采集请求接口(二维码)
	public static JSONObject startCaijiByCode(String token) {
		String url="https://www.juxinli.com/orgApi/rest/v4/creditcard/messages/qrcodeCollect/resp/";
		Map<String,String>map=new HashMap<String,String>();
		map.put("token", token);
		map.put("password", "");
		map.put("identity", "");
		map.put("type", "CONTROL");
		System.out.println(JSON.toJSONString(map));
		Object returnJson=HttpUtil.sendPostJsonData(url,JSON.toJSONString(map));
		System.out.println(returnJson);//字段1
		JSONObject jsonObject =JSONObject.parseObject(returnJson.toString());
		if("true".equals(jsonObject.getString("success"))){
			
		}
		return jsonObject;
	}
	
	//1.3.1根据采集TOKEN获取信用卡账单原始数据接口
	public static JSONObject GetCreditDataByToken(String token, String access_token) {
		String url="https://www.juxinli.com/api/get_credit_data";
		Map<String,String>map=new HashMap<String,String>();
		map.put("client_secret", client_secret);
		map.put("access_token", access_token);
		map.put("token", token);
		System.out.println(JSON.toJSONString(map));
		Object returnJson=HttpUtil.sendGet(url, map);
		System.out.println(returnJson);
		JSONObject jsonObject = JSONObject.parseObject(returnJson.toString());
		return jsonObject;
	}

	//1.1.1为调用其他接口，获得安全凭证码（access_report_token）
	public static JSONObject getCreditCardToken() {
		String url = "https://www.juxinli.com/api/v2/access_report_token?client_secret=" + client_secret + "&hours=24&org_name=juying";
		String res = HttpRequest.get(url).execute().body();
		System.out.println(res);
		JSONObject jsonObject =JSONObject.parseObject(res.toString());
		String access_token = jsonObject.getString("access_token");
		return jsonObject;
	}

	//1.2.1根据token获取数据采集状态接口
	public static void getCreditCardStatus(String access_token){
		String url = "https://www.juxinli.com/api/token_status?client_secret="+client_secret+"&org_name=juying";
		url = url + "&access_token="+access_token +"&token="+"";//startCaiji()生成的token
		String res = HttpRequest.get(url).execute().body();
		System.out.println(res);
		//JSONObject jsonObject =JSONObject.parseObject(res.toString());
	}


	public static void main(String[] args) {
	    //参数
		GetCreditDataByToken("aab6dc00494049a0a5ac10adc060ad78",access_token);
		
		
	}
}
